<template>
  <div>
    <el-upload
      class="upload-demo"
      drag
      multiple
      action="https://m2.yaolaivip.com/api/uploadFile/upload"
      :data="{token: token}"
      :show-file-list="true"
      :on-preview="onPreview"

      list-type="picture"
    >
      <i class="el-icon-upload"></i>
      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      <div class="el-upload__tip" slot="tip">不限制类型上传文件，完成后请点击保存地址</div>
    </el-upload>
    <input type="text" id="inputText" value="" />
  </div>
</template>
<script>
  export default {
    props: ['token'],
    data () {
      return {
      }
    },
    mounted () {
    },
    methods: {
      onPreview (file) {
        let resp = file.response
        if (resp) {
          var inputText = document.getElementById('inputText')
          var currentFocus = document.activeElement
          inputText.value = resp.data.realpath
          inputText.focus()
          inputText.setSelectionRange(0, inputText.value.length)
          document.execCommand('copy', true)
          currentFocus.focus()
          this.$message({
            message: '复制成功，请用ctrl + v粘贴',
            type: 'success'
          })
        } else {
          this.$message({
            message: '正在上传，请稍后',
            type: 'warning'
          })
        }
      }
    }
  }
</script>
<style lang="less" scoped>
  #inputText {
    position: fixed;
    left: -9999px;
    bottom: 0;
  }
</style>
